<!--论文隐匿名评审结果-->
<template>
    <div class="con">
        <div>
            <ConditionCard shadow="never" body-style="padding: 24px 24px 6px 24px;" @search="onSubmit" @reset="reset('queryForm')">
                <el-form ref="queryForm" label-suffix="：" :model="queryForm" label-position="right" label-width="120px">
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('label.schoolTerm')">
                                <CalendarSelect v-model="queryForm.yearTerm" @load-done="loadDone"></CalendarSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.grade')">
                                <el-date-picker v-model="queryForm.grade" value-format="yyyy" :clearable="true" type="year" :placeholder="$t('paperBlindTrial.gredeTips')" style="width: 100%" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.college')">
                              <el-select
                                v-model="queryForm.academyCode"
                                style="width: 100%;"
                                clearable
                                filterable
                                :placeholder="$t('common.text.all')"
                                v-clearreadonly
                              >
                                <el-option
                                    v-for="item in options.academyCode"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                              </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('courseSummary.major')">
                                <MyMajor :faculty="queryForm.academyCode" :filterable="true" :grade="queryForm.grade" v-model="queryForm.majorCode" :clearable="true" v-clearreadonly> </MyMajor>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.trainingLevel')" prop="eduLevel">
                                <DictSelect v-model="queryForm.eduLevel" :data="options.eduLevel" :clearable="true" ></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.trainingCategory')" prop="eduMode">
                                <DictSelect v-model="queryForm.eduMode" :filterable="true" :data="options.eduMode" :clearable="true" ></DictSelect>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('label.degreeCategory')" prop="degreeType">
                                <DictSelect v-model="queryForm.degreeType" :data="options.degreeType" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.formLearning')" prop="studyForm">
                                <DictSelect v-model="queryForm.studyForm" :data="options.studyForm" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('paperBlindTrial.sendCount')">
                              <DictSelect v-model="queryForm.evaCount" :data="options.passCount" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('paperBlindTrial.assessResult')">
                                <DictSelect v-model="queryForm.finalResult" :data="options.resultType" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('paperBlindTrial.batchName')">
                              <el-input v-model="queryForm.batchNo" :placeholder="$t('common.pla.pleaseInput')"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                          <el-form-item :label="$t('achievementApply.thesisTitle')">
                            <el-input v-model="queryForm.thesisTitle" :placeholder="$t('common.pla.pleaseInput')" :clearable="true"></el-input>
                          </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </ConditionCard>
            <el-card shadow="never" body-style="padding: 24px;">
              <h1 class="condition-title">{{$t('paperBlindTrial.reviewResultTitle')}}</h1>
              <div class="edu-opertion-bar">
                  <div class="float-left">
                      <KeywordInput v-model="queryForm.stuNoOrName" :placeholder="$t('achievementApply.tableIplaceholder')" @enter="search"></KeywordInput>
                  </div>
                  <div class="float-right">
                      <el-button type="primary" @click="exportData">{{$t('common.btn.export')}}</el-button>
                      <el-button type="primary" @click="batchDownload">{{$t('paperBlindTrial.batchDownload')}}</el-button>
                  </div>
              </div>
              <edu-table ref="tables" :url="tableApi"  @selection-change="handleSelectionChange">
                  <el-table-column :min-width="item.width" v-for="item in label" :key="item.props" :label="item.label" :prop="item.props" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <span v-if="item.props == 'evaCount'">{{scope.row.evaCount==0?'':scope.row.evaCount}}</span>
                      <!-- <span v-else-if="item.props == 'needPassCount'">{{scope.row.needPassCount==0?'':scope.row.needPassCount}}</span> -->
                      <span v-else>{{scope.row[item.props]}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column :min-width="100" :label="$t('paperBlindTrial.assessResult')" prop="finalResult" show-overflow-tooltip
                  :formatter="(row) => { return fieldChange(options.resultType, row.finalResult); }">
                  </el-table-column>
                  <!-- 导师不能录入成绩，只能查看  -->
                  <el-table-column width="130px" :label="$t('nonPublicCourseOpen.operation')" fixed="right">
                      <template slot-scope="scope">
                          <div class="con_btns">
                              <el-button type="text" v-if="!scope.row.finalResult" @click="showDialog('input', scope.row)">{{$t('paperBlindTrial.inputLabel')}}</el-button>
                              <el-button type="text" @click="showDialog('view', scope.row)">{{$t('message.Look')}}</el-button>
                          </div>
                      </template>
                  </el-table-column>
              </edu-table>
            </el-card>
        </div>
        <!-- 录入/查看评审详情 -->
        <el-dialog :visible.sync="dialogFlag" :title="titles" width="800px">
          <reviewDetails v-if="dialogFlag" :row="rows" ref="reviewDetails" :showMore="true" :viewState="typeInfo=='view'" @emit:back="backFunc"></reviewDetails>
          <span slot="footer" class="dialog-footer">
            <span v-if="typeInfo==='input'">
              <el-button @click="dialogFlag = false">{{$t('message.cancel')}}</el-button>
              <el-button type="primary" @click="sure">{{$t('message.confirm')}}</el-button>
            </span>
            <el-button v-else @click="dialogFlag = false">{{$t('common.btn.close')}}</el-button>
          </span>
        </el-dialog>
    </div>
</template>

<script>
import { resultTableList, resultTableExportTable, adminAuditDownloadZip } from "common/src/api/paperBlindTrial";
import MyMajor from "common/src/views/administrator/undergraduateTutor/component/MyMajor";
import commonMixins from 'common/src/views/practiceManagement/commonMixins';
import reviewDetails from '../concealedPaperReview/reviewDetails';
export default {
    components: {
        MyMajor,
        reviewDetails
    },
    mixins: [commonMixins],
    props: {},
    data() {
        return {
            tableApi: resultTableList,
            rows: {},
            yearTerms: '',
            queryForm: {
              yearTerm: '',
              grade: '',
              academyCode: '',
              majorCode: '',
              eduLevel: '',
              eduMode: '',
              degreeType: '',
              studyForm: '',
              evaCount: '',
              stuTutorNo: '',
              batchNo: '',
              finalResult: '',
              thesisTitle: '',
            },
            label: [
                { label: this.$t('label.stuCode'), props: 'stuNo', width: 90 },
                { label: this.$t('label.stuName'), props: 'stuName', width: 70 },
                { label: this.$t('label.grade'), props: 'grade', width: 80 },
                { label: this.$t('label.college'), props: 'academyName', width: 150 },
                { label: this.$t('courseSummary.major'), props: 'majorName', width: 150 },
                { label: this.$t('label.trainingLevel'), props: 'eduLevelI18n', width: 80 },
                { label: this.$t('label.trainingCategory'), props: 'eduModeI18n', width: 100 },
                { label: this.$t('label.degreeCategory'), props: 'degreeTypeI18n', width: 80 },
                { label: this.$t('label.formLearning'), props: 'studyFormI18n', width: 80 },
                { label: this.$t('achievementApply.thesisTitle'), props: 'thesisTitle', width: 130 },
                { label: this.$t('paperBlindTrial.batchName'), props: 'batchNo', width: 80 },
                { label: this.$t('paperBlindTrial.sendCount'), props: 'evaCount', width: 80 },
                { label: this.$t('paperBlindTrial.sendTime'), props: 'evaDate', width: 155 },
                { label: this.$t('paperBlindTrial.needPassNum'), props: 'needPassCount', width: 90 },
                // { label: this.$t('paperBlindTrial.reviewCount'), props: 'reviewCount', width: 150 },
            ],
            options: {
              majorCode: [], // 专业
              academyCode: [], // 学院
              eduLevel: [], // 培养层次
              eduMode: [], // 培养类别
              degreeType: [], // 学位类型
              studyForm: [], // 学习形式
              passCount: [], // 送审次数
              resultType: [] // 评审结果
            },
            dialogFlag: false,
            typeInfo: '',
            titles: this.$t('paperBlindTrial.inputLabel'),
            selectionDatas: []
        };
    },
    computed: {

    },
    created() {

    },
    mounted() {
      let param = {
        X_YX: 'academyCode', // 学院
        X_PYCC: 'eduLevel', // 培养层次
        X_PYLB: 'eduMode', // 培养类别
        X_XWLX: 'degreeType', // 学位类型
        K_XXXS: 'studyForm', // 学习形式
        BLIND_REVIEW_RESULT: 'resultType', // 评审结果字典
      };
      this.initOptions(param);
      this.onSubmit();
      for (let i = 1; i <= 50; i++) {
        let obj = { label: i, value: i, id: i };
        this.options.passCount.push(obj);
      }
    },
    methods: {
        exportData() { // 导出
          let jsons = this.$refs.tables.selectionDatas;
          let param = {};
          let fileName = '';
          if (jsons && jsons.length > 0) { // 优先按勾选内容导出
            param.ids = jsons.map(v => v.resultId);
            param.type = 1;
          } else { // 存在搜索条件时则按搜索条件导出
            // fileName =
            param.request = this.queryForm;
            param.type = 0;
          }
          resultTableExportTable(param);
        },
        showDialog(val, row) {
          this.titles = val == 'input' ? this.$t('paperBlindTrial.inputLabel') : this.$t('message.Look');
          this.dialogFlag = true;
          this.typeInfo = val;
          row.evaExpertCount = 3;
          this.rows = row;
        },
        onSubmit() { // 筛选
          this.$refs.tables.pageNum = 1;
          this.$refs.tables.search(this.queryForm);
        },
        reset() {  // 重置
          for (const key in this.queryForm) {
            if (key !== 'yearTerm') {
              this.queryForm[key] = '';
            }
          }
          this.queryForm.yearTerm = this.yearTerms;
          this.onSubmit();
        },
        search() { // 搜索
          this.queryForm.stuNoOrName = this.queryForm.stuNoOrName.trim();
          this.onSubmit();
        },
        loadDone() { // 页面加载时保存学期学年
          this.yearTerms = this.queryForm.yearTerm;
        },
        // 录入成绩确定
        sure() {
          this.$refs.reviewDetails.save();
        },
        // 多选方法
        handleSelectionChange (val) {
          this.selectionDatas = val;
        },
        backFunc () {
          this.dialogFlag = false;
          this.onSubmit();
        },
        // 批量下载
        batchDownload () {
          // if (this.selectionDatas.length === 0) {
          //   this.$message.error(this.$t('paperBlindTrial.downLoadTips'));
          //   return;
          // }
          let param = _.cloneDeep(this.queryForm);
          param.applyIds = this.selectionDatas.map(v=>v.applyId);
          adminAuditDownloadZip(param);
        }
    }
};
</script>

<style scoped lang="scss">
.con {
    &_searchRight {
        margin-left: 10px;
    }
}
.condition-title {
  color: #2b3b4e;
  font-size: 18px;
  line-height: 24px;
  font-weight: bold;
}
</style>

